package com.javashow.login.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.javashow.login.service.ILoginService;
import com.javashow.pojo.User;

@Controller
public class LoginController {
	
	@Autowired
	private ILoginService loginService;
	
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public ModelAndView login(HttpServletRequest request) {
		ModelAndView result = new ModelAndView();
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		User user = new User();
		user.setUsername(username);
		user.setPassword(password);
		if(loginService.login(user)) {
			result.setViewName("index");
		} else {
			result.setViewName("login/login");
		}
		
		return result;
	}
	
	@RequestMapping(value = "/extjsAjax", method = RequestMethod.POST)
	public ModelAndView extAjax(HttpServletRequest request) {
		String data = request.getParameter("data");
		System.out.println(data);
		return null;
	}
}
